﻿var g_BlockIMG = "../../images/loading.gif";//Grid Loading
var prog_name = "krj_tracking_detail.js";
function SelectRows() {
    try
    {
        if (!$(".SelectedRow").length > 0) {
            alert('請選取一筆資料!!');
            return false;
        }
        else {
            var w = window.open("~/Management/Tracking/TEST.aspx", '', 'width=1000,height=600,toolbar=0,status=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1');
            w.focus();
        }
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "SelectRows", "USER", "js", err);
        return false;
    }
}
 
function btnSearch_Click(p_PageIndex) {
    try
    {
        var sORDER = '';
        sORDER = 'F2156B desc';
        //頁次
        var m_PageIndex = getPageIndex(p_PageIndex);
        //alert($("#MainContent_TabContainer2_TabPanel5_lblDetail_NO").html());
        //查詢條件 對應後端查詢條件
        var StrWhere = { DETAIL_NO: $("#MainContent_TabContainer2_TabPanel5_lblDetail_NO").html(), ITEM_NO: $("#MainContent_TabContainer2_TabPanel5_lblITEM_NO").html() };
        $("#DocumentPageControl").attr("GridWidth", "12%,10%,10%,15%,18%,10%,20%");
        $("#DocumentPageControl").attr("textalign", "C,C,C,C,L,C,C");
        $("#DocumentPageControl").attr("HideColumn", "DETAIL_NO,ITEM_NO");
        //組Grid 公用Function 後端網頁名稱, 查詢FUNCTION名稱, 頁次, 一頁筆數, 排序條件, 查詢條件, 目標 DIV
        gdb_DataBind("krj_tracking_detail", "GetCorrection", m_PageIndex, "5", sORDER, StrWhere, "Document");

        $("input[id*='btnShowPopup']").attr("disabled", true);
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "btnSearch_Click", "USER", "js", err);
        return false;
    }
}
function GetCorrection(sender, e) {
    try
    {
        //alert(sender.get_activeTab().get_tabIndex());
        if (sender.get_activeTab().get_tabIndex() == 4) {
            btnSearch_Click();
        }
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "GetCorrection", "USER", "js", err);
        return false;
    }

}
function GetTab(sender, e) {
    try
    {
        //將Grid有選擇的項目清空
        $(".SelectedRow").removeClass("SelectedRow");
        $("input[id*='btnShowPopup']").attr("disabled", true);

        //$(".SelectedRow").removeClass("SelectedRow");
        if (sender.get_activeTab().get_tabIndex() == 1) {
            var sImageurl = $("input[id*='hidImage_URL']").val();
            $("img[id*='Image1']").attr("src", sImageurl);
            //判斷圖片大小大於800時縮圖
            var imgW = $("img[id*='Image1']").width();
            var imgH = $("img[id*='Image1']").height();
            if (imgW > 800) {
                var per = 800 / imgW;
                $("img[id*='Image1']").width(imgW * per);
                $("img[id*='Image1']").height(imgH * per);
            }
        
        
        }
        //路線貨件處理查詢
        if (sender.get_activeTab().get_tabIndex() == 2) {
            //判斷是否已有資料
            if (typeof($("#Tracking_Grid")[0]) == 'undefined') {
                var sORDER = 'CHECKING_DATE';
                sORDER = '';
                //頁次
                //$("span[id*='lblDetail_NO']").text()
                var StrWhere = { DETAIL_NO: $("input[id*='hidDetail_NO']").val(), ITEM_NO: $("input[id*='hidITEM_NO']").val(), History: $("input[id*='hidHistory']").val() };
                $("#TrackingPageControl").attr("GridWidth", "9%,8%,6%,7%,8%,15%,10%,10%,12%,7%,8%");
                $("#TrackingPageControl").attr("textalign", "C,C,C,C,C,C,C,C,C,C,C");
                $("#TrackingPageControl").attr("HideColumn", "");
                //組Grid 公用Function 後端網頁名稱, 查詢FUNCTION名稱, 頁次, 一頁筆數, 排序條件, 查詢條件, 目標 DIV
                gdb_DataBind("krj_tracking_detail", "GetTracking", 1, "15", sORDER, StrWhere, "Tracking");
            }

        }

        //照會資料查詢
        if (sender.get_activeTab().get_tabIndex() == 3) {
            //判斷是否已有資料
            if (typeof ($("#Checking_Grid")[0]) == 'undefined') {
                var sORDER = '';
                sORDER = 'F26201 desc,F26202 desc';
                //頁次
                //$("span[id*='lblDetail_NO']").text()
                var StrWhere = { DETAIL_NO: $("input[id*='hidDetail_NO']").val(), ITEM_NO: $("input[id*='hidITEM_NO']").val() };
                $("#CheckingPageControl").attr("GridWidth", "10%,10%,10%,10%,10%,15%,25%,10%");
                $("#CheckingPageControl").attr("textalign", "C,C,C,C,C,C,C,C");
                $("#CheckingPageControl").attr("HideColumn", "");
                //組Grid 公用Function 後端網頁名稱, 查詢FUNCTION名稱, 頁次, 一頁筆數, 排序條件, 查詢條件, 目標 DIV
                gdb_DataBind("krj_tracking_detail", "GetChecking", 1, "13", sORDER, StrWhere, "Checking");
            
            }

        }
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "GetTab", "USER", "js", err);
        return false;
    }

}
function send() {
    try
    {
        var sMailaddress = $("input[id*='txtEMAIL']").val();
        if (sMailaddress == "") {
            $("input[id*='txtEMAIL']").focus();
            alert("請輸入Email Address！");
            return false;
        }
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "send", "USER", "js", err);
        return false;
    }
}
function getORGDETAIL(stype) {
    try
    {
        //將Grid有選擇的項目清空
        $(".SelectedRow").removeClass("SelectedRow");
        $("input[id*='btnShowPopup']").attr("disabled", true);
        //$(".Document")[0].removeClass("SelectedRow");

        var sDETAIL_NO = "", sITEM_NO = "", sCORRECT_NO = "";
        sDETAIL_NO = $("input[id*='hidDetail_NO']").val();
        sITEM_NO = $("input[id*='hidITEM_NO']").val();
        sCORRECT_NO = $("input[id*='hidCORRECT_NO']").val();
    
        if (stype == "1") {
            //原進入Detail狀況
            setColumns(sDETAIL_NO, sCORRECT_NO, sITEM_NO, "", sCORRECT_NO,"NEW");
        
        }
        else {
            //原託運單
            setColumns(sDETAIL_NO, "", sITEM_NO, "", "","");
        
        }
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "getORGDETAIL", "USER", "js", err);
        return false;
    }
}
function sendmail() {
    try
    {
        //var sMailaddress = $("input[id*='txtEMAIL']").val();
        var param1 = "vicky@ddsc.com.tw";
        $.ajax({
            type: "POST",
            url: "krj_tracking_detail.aspx/sendmail",
            data: "{'param1' : '" + param1 + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            error: function (xmlHttpRequest, error) {
                var m_ErrMessage = xmlHttpRequest.responseText;
                alert(m_ErrMessage);
            },
            success: function (msg) {
                alert(msg.d);
            }
        });
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "sendmail", "USER", "js", err);
        return false;
    }
}
function setColumns(sDetail_NO, sCorrect_NO, sITEM_NO, sRECEIVED_DEPT, s_Pre_Correct_NO,sTYPE) {
    try
    {
    var sStatus = "", sORG_SHIPPING_NO = "";
    sORG_SHIPPING_NO = $.trim($("input[id*='hidORG_SHIPPING_NO']").val());
    sHistory = $.trim($("input[id*='hidHistory']").val());
    if (sCorrect_NO == "") {
        sStatus = "-(原託運單)";
    }
    else {
        if (sCorrect_NO == s_Pre_Correct_NO) {
            sStatus = "";
        }
        else {
            sStatus = "-(更正單號:" + sCorrect_NO +")";
        }
    }

    $('div.' + 'Document').block({
        fadeIn: 700,
        fadeOut: 700,
        message: "<img src=\"" + g_BlockIMG + "\" /> ", css: {
            border: 'none',
            padding: '0px',
            opacity: .8
        },
        overlayCSS: { backgroundColor: g_BlockBG },
        onBlock: function () {
            $.ajax({
                type: "POST",
                url: "krj_tracking_detail.aspx/selectedrow",
                data: "{'DETAIL_NO' : '" + sDetail_NO + "','CORRECT_NO' : '" + sCorrect_NO + "','ITEM_NO' : '" + sITEM_NO + "','ORG_SHIPPING_NO' : '" + sORG_SHIPPING_NO + "','sTYPE' : '" + sTYPE + "','History' : '" + sHistory + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                error: function (xmlHttpRequest, error) {
                    var m_ErrMessage = xmlHttpRequest.responseText;
                   
                    MsgBlock("Document", m_ErrMessage, false);

                },
                success: function (data) {
                    //alert(data.d);
                    //data.d[0].CORRECT_DEPT
                    if (data != null) {
                        if (data.d.indexOf("error") >= 0) {
                            if (data.d.indexOf("error_no") < 0) {
                                alert(data.d.replace("error", ""));
                            }
                        }
                        else {

                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDetail_NO']").text(data.d[0].F63101);//明細單號
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblITEM_NO']").text(data.d[0].F63102);//貨號
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblCANCEL']").text(data.d[0].f20602_1);//銷卡
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblSTOCK']").text(data.d[0].f20602_2);//存庫
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDISPATCH_DATE']").text(data.d[0].F63103);//發送日
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblRECEIVED_DATE']").text(data.d[0].F63105);//到著日
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDelivery_Note']").text(data.d[0].F631B4);//出貨單號
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDISPATCH_DEPT']").text(data.d[0].F21504 + " " + data.d[0].DISPATCH_DEPT);//發送站
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblRECEIVED_DEPT']").text(data.d[0].F21510 + " " + data.d[0].RECEIVED_DEPT);//到著站
                            //$("span[id='MainContent_TabContainer2_TabPanel5_lblCORRECT_DATE']").text(data.d[0].F21509);//更正日
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblSHIPPING_NO_1']").text(data.d[0].F631A1);//託運單號
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblPAYMENT_NO_1']").text(data.d[0].F63117);//付款人編號
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblCORRECT_NO']").text(s_Pre_Correct_NO);//更正單號
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblSHIPPER']").text(data.d[0].F21526);//更正托運人
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblRECEIVER']").text(data.d[0].F21527);//更正收貨人
                            if (sRECEIVED_DEPT != "") {
                                $("span[id='MainContent_TabContainer2_TabPanel5_lblCORRECT_DEPT']").text(sRECEIVED_DEPT);//更正後所站
                            }
                            else
                                $("span[id='MainContent_TabContainer2_TabPanel5_lblCORRECT_DEPT']").text(data.d[0].F21524 + " " + data.d[0].CORRECT_DEPT);//更正後所站

                            //$("span[id='MainContent_TabContainer2_TabPanel5_lblCORRECT_DEPT']").text(data.d[0].F21524 + " " + data.d[0].CORRECT_DEPT);//更正後所站
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblORG_PAYMENT']").text(data.d[0].F2156F);//原訂代收款
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblSPECIFIED_SECTIONS']").text(data.d[0].F631C1);//指送時段
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblSPECIFIED_DATE']").text(data.d[0].F63107);//指送日期
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblPROJECT']").text(data.d[0].F631B3);//行銷專案
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblPAYMENT']").text(data.d[0].F21532);//支付
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblSHIPPING_AMOUNT']").text(data.d[0].F21533);//運費
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblPAY_AMOUNT']").text(data.d[0].F21575);//報值費
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblITEM_COUNT']").text(data.d[0].F21529);//件數
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblTRANS_CODE']").text(data.d[0].F2157A);//運選碼
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblPAY1']").text(data.d[0].F21534);//接費
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblPAY2']").text("");//挽工費
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblWEIGHT']").text(data.d[0].F21530);//重量
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblAMOUNT1']").text(data.d[0].F21579);//報值額
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblAMOUNT2']").text(data.d[0].F21535);//送費
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblAMOUNT3']").text(data.d[0].F21574);//特服費
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblCubic']").text(data.d[0].F21531);//才數
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblCODE1']").text(data.d[0].F21572);//特服碼1
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblAMOUNT4']").text(data.d[0].F21536);//代款
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblAMOUNT5']").text(data.d[0].F63140);//小計
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblAddition']").val(data.d[0].F631B5);//加成
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblTRANS_USER_ID']").text(data.d[0].F61977);//發送運輸單
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblRECEIVE_USER_ID']").text(data.d[0].F61971);//受付員
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblCREATE_USER_ID']").text(data.d[0].F61973);//登錄員


                            $("span[id='MainContent_TabContainer2_TabPanel5_lblCheckUSER_ID']").text(data.d[0].F63155);//點貨人員
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblCheckUSER_NAME']").text(data.d[0].CHECK_USER_NAME);//點貨人員姓名
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblCheck_COUNT']").text(data.d[0].F63156);//點卸件數
                            $("span[id*='MainContent_TabContainer2_TabPanel5_lblBroken_COUNT']").text(data.d[0].F63158);//破損件數
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblCheck_date']").text(data.d[0].F63151);//點貨日期
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblCheck_time']").text(data.d[0].F6315C);//點貨時間


                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDRIVER_Distr']").text(data.d[0].F6318A);//攜出人員
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDRIVER_Distr_NAME']").text(data.d[0].Distr_NAME);//攜出人員姓名
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDISTR_COUNT']").text(data.d[0].F63187);//件數
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDISTR_DATE']").text(data.d[0].F6318B);//攜出日期
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDISTR_TIME']").text(data.d[0].F6318C);//攜出時間

                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDRIVER_REACH']").text(data.d[0].F63167);//駕駛員
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDISPATCH_DRIVER_NAME']").text(data.d[0].DISPATCH_DRIVER_NAME);//駕駛員姓名
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblREACH_COUNT']").text("");//件數
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblREACH_DATE']").text(data.d[0].F63161);//銷卡日期
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblREACH_TIME']").text(data.d[0].F6316C);//銷卡時間


                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDRIVER_STOCK']").text(data.d[0].F63177);//駕駛員
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblDRIVER_STOCK_NAME']").text(data.d[0].STOCK_NAME);//駕駛員姓名
                            $("span[id='MainContent_TabContainer2_TabPanel5_lbl_DAMAGE_COUNT_3']").text("");//件數
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblSTOCK_DATE']").text(data.d[0].F63171);//存庫日期
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblSTOCK_TIME']").text(data.d[0].F6317C);//存庫時間

                            $("span[id='MainContent_TabContainer2_TabPanel5_lblADDRESS']").text(data.d[0].F21703);//地址
                            $("span[id='MainContent_TabContainer2_TabPanel5_lblREASON']").text(data.d[0].F21704);//原因
                        }
                    }
                    $("#MainContent_TabContainer2_TabPanel5_lblSTATS").html(sStatus);
                    unblockUI("Document");
                }

            });
        }
    });
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "setColumns", "USER", "js", err);
        return false;
    }
}
//更正明細選擇一筆
function selectedEvent(e, p_TargetDiv) {
    try
    {
        //擷取觸發控制項
        var obj = GetEvent(e)
        var sDetail_NO = "";
        var sITEM_NO = "";
        var sCorrect_NO = "", s_Pre_Correct_NO = "";
        var sRECEIVED_DEPT = "";
        var rownum = 0;
        if (obj.tagName == "TD") {
            //var m_TrId = $("#" + obj.id).parent()[0].id;
            //上一筆更正單號
            rownum = $("#" + obj.id).parent()[0].rowIndex;
            if(rownum > 0)
            {
                s_Pre_Correct_NO = $.trim($("#" + obj.id).parent().parent()[0].rows[rownum - 1].cells[5].innerText);
            }
            sCorrect_NO = $.trim($("#" + obj.id).parent()[0].cells[5].innerText); //更正單號
            sDetail_NO = $.trim($("#" + obj.id).parent()[0].cells[7].innerText);  //明細單號
            sITEM_NO = $.trim($("#" + obj.id).parent()[0].cells[8].innerText); //貨號
            sRECEIVED_DEPT = $.trim($("#" + obj.id).parent()[0].cells[0].innerText); //到著站
        
            setColumns(sDetail_NO, sCorrect_NO, sITEM_NO, sRECEIVED_DEPT, s_Pre_Correct_NO,"");
        
            //Enable Button
            $("input[id*='btnShowPopup']").attr("disabled", false);
        

        }

    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "selectedEvent", "USER", "js", err);
        return false;
    }
}
function getCorrected() {
    try
    {
        var sMailaddress = $("input[id*='txtEMAIL']").val();
        //var param1 = "vicky@ddsc.com.tw";
        $.ajax({
            type: "POST",
            url: "krj_tracking_detail.aspx/sendmail",
            data: "{'param1' : '" + sMailaddress + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            error: function (xmlHttpRequest, error) {
                var m_ErrMessage = xmlHttpRequest.responseText;
                alert(m_ErrMessage);
            },
            success: function (msg) {
                alert(msg.d);
            }
        });
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "getCorrected", "USER", "js", err);
        return false;
    }
}

function showModalPopupViaClient(ev) {
    
    try
    {
        var CORRECTION_NO = "", sLBLNO = "";
        if (!$(".SelectedRow").length > 0) {
            alert('請選取一筆資料!!');
            return false;
        }
        CORRECTION_NO = $(".SelectedRow")[5].innerText;
        //CORRECTION_NO = "4466311";
        RECEIVED_DEPT = $(".SelectedRow")[0].innerText;
        //託運單號
        sLBLNO = $("input[id*='hidDetail_NO']").val() + $("input[id*='hidITEM_NO']").val();
        

        //將值放入畫面
        $("input[id*='txtCORRECTION_NO']").val(CORRECTION_NO);
        //託運單號
        $("input[id*='txtSHIPPING_NO_1']").val(sLBLNO);
        $("input[id*='txtRECEIVED_DEPT_1']").val(RECEIVED_DEPT);
        

        var sORDER = '';
        sORDER = '';
        //頁次
        //alert($("#MainContent_TabContainer2_TabPanel5_lblDetail_NO").html());
        //查詢條件 對應後端查詢條件
        var StrWhere = { CORRECT_NO: CORRECTION_NO };
        $("#mislandedPageControl").attr("GridWidth", "10%,10%,10%,10%,10%,20%,10%,20%");
        $("#mislandedPageControl").attr("textalign", "C,C,C,C,C,C,C,C");
        $("#mislandedPageControl").attr("HideColumn", "");
        //組Grid 公用Function 後端網頁名稱, 查詢FUNCTION名稱, 頁次, 一頁筆數, 排序條件, 查詢條件, 目標 DIV
        gdb_DataBind("krj_tracking_detail", "Getmislanded", "1", "10", sORDER, StrWhere, "mislanded");

       
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "showModalPopupViaClient", "USER", "js", err);
        return false;
    }
}

function hideModalPopupViaClient(ev) {
    //var modalPopupBehavior = $("#ModalPopupExtender1");
    //modalPopupBehavior.hide();
    
}

//照會明細選擇一筆
function selectedchecking(e, p_TargetDiv) {
    try
    {
        //擷取觸發控制項
        var obj = GetEvent(e)
        var sCHECKING_NO = "";
        var sCHECKING_SEQ = "";
        var rownum = 0;
        if (obj.tagName == "TD") {
            //var m_TrId = $("#" + obj.id).parent()[0].id;
            //上一筆更正單號
            rownum = $("#" + obj.id).parent()[0].rowIndex;
        
            sCHECKING_NO = $.trim($("#" + obj.id).parent()[0].cells[3].innerText); //照會單號
            sCHECKING_SEQ = $.trim($("#" + obj.id).parent()[0].cells[4].innerText);  //照會序號
        
            setCheckingColumns(sCHECKING_NO, sCHECKING_SEQ);
        
        }
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "selectedchecking", "USER", "js", err);
        return false;
    }
    
}
function setCheckingColumns(sCHECKING_NO, sCHECKING_SEQ) {
    try
    {
    var sStatus = "", sORG_SHIPPING_NO = "";
    
    $('div.' + 'Checking').block({
        fadeIn: 700,
        fadeOut: 700,
        message: "<img src=\"" + g_BlockIMG + "\" /> ", css: {
            border: 'none',
            padding: '0px',
            opacity: .8
        },
        overlayCSS: { backgroundColor: g_BlockBG },
        onBlock: function () {
            $.ajax({
                type: "POST",
                url: "krj_tracking_detail.aspx/selectchecking",
                data: "{'CHECKING_NO' : '" + sCHECKING_NO + "','CHECKING_SEQ' : '" + sCHECKING_SEQ + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                error: function (xmlHttpRequest, error) {
                    var m_ErrMessage = xmlHttpRequest.responseText;

                    MsgBlock("Document", m_ErrMessage, false);

                },
                success: function (data) {
                    //alert(data.d);
                    //data.d[0].CORRECT_DEPT
                    if (data != null) {
                        if (data.d.indexOf("error") >= 0) {
                            if (data.d.indexOf("error_no") < 0) {
                                alert(data.d.replace("error", ""));
                            }
                            else {
                                //清空欄位
                                $("span[id*='MainContent_TabContainer2_TabPanel1_lbl']").each(function () {
                                   
                                    $(this)[0].val("");
                                    
                                });

                            }
                        }
                        else {
                            $("#div_checking").show();
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblCHECKING_NO']").text(sCHECKING_NO);//照會單號
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblCHECKING_SEQ']").text(sCHECKING_SEQ);//照會序號

                            $("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_DEPT']").text(data.d[0].F26203);//照會單位
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_ER']").text(data.d[0].F26225);//照會人
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_TIME']").text(data.d[0].F26205);//照會時間

                            $("span[id='MainContent_TabContainer2_TabPanel1_lblReply_Dept']").text(data.d[0].F26207);//答覆單位
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblReply_ER']").text(data.d[0].F26239);//答覆人
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblReply_TIME']").text(data.d[0].F26240);//答覆時間
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblReply_Flag']").text(data.d[0].F26223);//答覆時間

                            $("span[id='MainContent_TabContainer2_TabPanel1_lblClosed_Dept']").text(data.d[0].F26203_1);//結案單位
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblClosed_ER']").text(data.d[0].F26230);//結案人
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblClosed_TIME']").text(data.d[0].F26231);//結案時間
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblClosed_Flag']").text(data.d[0].F26224);//結案時間


                            $("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_REASON_1']").text(data.d[0].F26208);//照會原因1
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_REASON_2']").text(data.d[0].F26235);//照會原因2

                            var Checking_REASON = "";

                            Checking_REASON = data.d[0].F26304_1 + "<br />";
                            Checking_REASON = Checking_REASON + data.d[0].F26304_2 + "<br />";
                            Checking_REASON = Checking_REASON + data.d[0].F26304_3 + "<br />";
                            Checking_REASON = Checking_REASON + data.d[0].F26304_4 + "<br />";
                            Checking_REASON = Checking_REASON + data.d[0].F26304_5 + "<br />";
                            Checking_REASON = Checking_REASON + data.d[0].F26304_6;
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_REASON']").html(Checking_REASON);//照會原因3
                            //$("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_REASON_4']").text(data.d[0].F26304_2);//照會原因4
                            //$("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_REASON_5']").text(data.d[0].F26304_3);//照會原因5
                            //$("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_REASON_6']").text(data.d[0].F26304_4);//照會原因6
                            //$("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_REASON_7']").text(data.d[0].F26304_5);//照會原因7
                            //$("span[id='MainContent_TabContainer2_TabPanel1_lblChecking_REASON_8']").text(data.d[0].F26304_6);//照會原因8
                            var Reply_REASON = "";

                            Reply_REASON = data.d[0].F26404_1 + "<br />";
                            Reply_REASON = Reply_REASON + data.d[0].F26404_2 + "<br />";
                            Reply_REASON = Reply_REASON + data.d[0].F26404_3 + "<br />";
                            Reply_REASON = Reply_REASON + data.d[0].F26404_4 + "<br />";
                            Reply_REASON = Reply_REASON + data.d[0].F26404_5 + "<br />";
                            Reply_REASON = Reply_REASON + data.d[0].F26404_6;
                            
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblReply_REASON']").html(Reply_REASON);//答覆說明1
                           //$("span[id='MainContent_TabContainer2_TabPanel1_lblReply_REASON_2']").text(data.d[0].F26404_2);//答覆說明2
                            //$("span[id='MainContent_TabContainer2_TabPanel1_lblReply_REASON_3']").text(data.d[0].F26404_3);//答覆說明3
                            //$("span[id='MainContent_TabContainer2_TabPanel1_lblReply_REASON_4']").text(data.d[0].F26404_4);//答覆說明4
                            //$("span[id='MainContent_TabContainer2_TabPanel1_lblReply_REASON_5']").text(data.d[0].F26404_5);//答覆說明5
                            //$("span[id='MainContent_TabContainer2_TabPanel1_lblReply_REASON_6']").text(data.d[0].F26404_6);//答覆說明6
                            
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblDISPATCH_DEPT4']").text(data.d[0].F26215);//發送站
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblRECEIVED_DEPT4']").text(data.d[0].F26233);//到著站
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblDetail_NO4']").text(data.d[0].F26209);//明細單號
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblITEM_NO4']").text(data.d[0].F26210);//貨號
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblSHIPPER4']").text(data.d[0].F26211);//託運人名稱
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblRECEIVER4']").text(data.d[0].F26212);//收貨人
                            $("span[id='MainContent_TabContainer2_TabPanel1_lblDISTR_COUNT4']").text(data.d[0].F26213);//件釋

                        }
                    }
                    
                    unblockUI("Checking");
                }

            });
        }
    });
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "setCheckingColumns", "USER", "js", err);
        return false;
    }
}